<?php
//首页显示
namespace newMobile\Controller;
use Think\Controller;
class SearchController extends CommonController {
    public function index(){
    	
		$_GET = array_merge($_GET, $_POST);
		$keywords = $_GET['keyword'];
		
		if($keywords === iconv('UTF-8', "utf-8", iconv("utf-8", 'UTF-8', $keywords))){
			$keywords=$keywords;
		}else{
			$keywords= iconv("gbk","utf-8",$keywords);
		}
		if($keywords==null){
    		$this->error('关键词不能为空！'.$keywords);
    	}else{
			$this->assign('keywords',$keywords);
		}
		$this->display();
    }	
    
    function ajax_getshop(){
    	
		$keyword=I('post.keyword');
    	$order=I('post.order',0);
    	$last=I('post.last');
    	$amount=I('post.amount');
    	$where_lianhe="ishidden=0 and title like '%$keyword%'";//联合查询条件
	    $orders_arr=array(
   			'0' => 'id desc', 
   			'1' => 'sale_num desc', 
   			'2' => 'click_num desc', 
   			'3' => 'price desc', 
   			'4' => 'price asc', 
   		);
   		
	    $shop=M('shop');
	   
		$rs=$shop->where($where_lianhe)->order($orders_arr[$order])->limit($last,$amount)->select();
		
		
		foreach($rs as $key=>$value){
	   		 $res[]['info'] = '<li><div class="item"><div class="pic_box"></div><div class="goods_images"><a href="'.U('shop/index',array('id'=>$value['id'])).'"><img src="'.$value['image'].'"></a></div><dl><dt><a href="'.U('shop/index',array('id'=>$value['id'])).'">'.$value['title'].'</a></dt><dd><i>￥'.$value['price'].'</i><em>￥'.$value['oprice'].'</em> </dd><span>已售'.$value['sale_num'].'件</span></dl></div><!--列表页面加减号--></li>';
	    }
	    $this->ajaxReturn($res);
	}
}
?>
